package com.group.admin.xxl;

import com.group.admin.dao.ShopCommodityDao;
import com.group.admin.entity.ShopCommodityEntity;
import com.group.admin.service.ShopCommodityService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class AdminXxl {
    @Autowired
    ShopCommodityDao shopCommodityDao;
    /**
     * 2、分片广播任务
     */
    @XxlJob("adminxxx")
    public void adminxxx() throws Exception {


        // 分片参数
        //分片序号 0 1
        int shardIndex = XxlJobHelper.getShardIndex();
        //分片总数 2
        int shardTotal = XxlJobHelper.getShardTotal();

        List<ShopCommodityEntity> entities= shopCommodityDao.sel(shardIndex,shardTotal);
        log.info("分片："+shardIndex+" 执行查询，这是查出的数据");
        for (ShopCommodityEntity entity : entities) {
            System.out.println(entity.toString());
        }



//        for (int i = 1 ;  i < 10 ; i++) {
//            if (i % shardTotal == shardIndex){
//
//                System.out.println("分片参数：当前分片序号 = {"+shardIndex+"}, 总分片数 = {"+shardTotal+"},当前任务："+i);
//            }
//        }
    }
}
